package com.xpec.c4.service.group.transportlayer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.service.message.MessageAction;

/**
 * @author zhangyuan
 *
 *	thread backed broadcasting worker 
 */
public class BroadcastTask implements Runnable {
	
	/**
	 * broadcast this
	 */
	private GroupMessage content = null;
	
	private static final Log log = LogFactory.getLog(BroadcastTask.class);

	private static ExecutorService executor = Executors.newFixedThreadPool(4);
	
	public static void execute(Runnable command)
	{
		executor.execute(command);
	}
	
	public BroadcastTask(GroupMessage content) {
		super();
		this.content = content;
	}

	@Override
	public void run() 
	{
		try
		{
			MessageAction.boardCastMessage(content, content.getMessageType(),
					content.getMessageContentBytes());
		}
		catch(Exception e)
		{
			log.error(e, e);
		}
	}

}
